package com.gitee.wsl.serialization

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.AbstractEncoder
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.modules.SerializersModule
import kotlin.time.Duration

@OptIn(ExperimentalSerializationApi::class)
public class KotlinXValueFinder(
    public val field: String,
    override val serializersModule: SerializersModule = SerializersModule { }
) : AbstractEncoder() {

    public var result: Any? = null

    override fun encodeElement(descriptor: SerialDescriptor, index: Int): Boolean {
        return descriptor.getElementName(index) == field
    }

    override fun encodeValue(value: Any) {
        result = value
    }
}